// Copyright 2008 David Mitchell
// Released under the MIT License

using System;
using System.Reflection;

namespace NSDuctTape
{
	internal static class MemberInfoUtility
	{
		public static T GetCustomAttribute<T>(MemberInfo info)
			where T: Attribute
		{
			object[] attributes = info.GetCustomAttributes(typeof(T), false);
			return attributes.Length == 1 ? attributes[0] as T : null;
		}

		public static T[] GetCustomAttributes<T>(MemberInfo info)
			where T: Attribute
		{
			return Enumerable.ToArray(
				Enumerable.Select<object, T>(
					info.GetCustomAttributes(typeof(T), false),
					delegate(object o) { return o as T; }));
		}
	}
}
